/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t_frcmd_talking.c                                  */
/*  NOTE      =                                                    */
/*  DATE      = 2014/12/15 by geyh                                 */
/*******************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>
#include <protobuf-c/protobuf-c.h>

#include "../../comm/frcmd_parse_detail.h"
#include "../../comm/client.pb-c.h"
#include "../../comm/frcmd_parse.h"
#include "../../comm/apm.pb-c.h"
#include "../../comm/frcmd_client.h"
#include "../../comm/frcomm.h"
#include "../../comm/frmem.h"
#include "../../comm/frsutl.h"
#include "../../comm/apmtest_cunit.h"

static int __suite_init(void)
{

	return 0;
}

static int __suite_cleanup(void)
{

	return 0;
}

extern int g_i_port;
extern char* g_p_server;

void case1(void)
{
    char *p_cmd = "-c setup l7 add tcp 192.168.0.1 80 http;";
    unsigned int ui_cmdlen = 40;
    char *p_response = NULL;
    int i_ret = 0;

    g_i_port = 65535;
    g_p_server = "127.0.0.1";

    i_ret = frcmd_talking(p_cmd, ui_cmdlen, &p_response);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
 //   printf("%s",p_response);
    frfree(p_response);

}

void case2(void)
{
    char *p_cmd = "-c setup filter add tcp 192.168.0.1-192.168.0.20 80-100 0.0.0.0;";
    unsigned int ui_cmdlen = 65;
    char *p_response = NULL;
    int i_ret = 0;

    g_i_port = 65535;
    g_p_server = "127.0.0.1";

    i_ret = frcmd_talking(p_cmd, ui_cmdlen, &p_response);

    CU_ASSERT_EQUAL(i_ret,FR_SUCC);
 //   printf("%s",p_response);
    frfree(p_response);

}

void case3(void)
{
    char *p_cmd = NULL;
    unsigned int ui_cmdlen = 0;
    char *p_response = NULL;
    int i_ret = 0;

    g_i_port = 65535;
    g_p_server = "127.0.0.1";

    i_ret = frcmd_talking(p_cmd, ui_cmdlen, &p_response);

    CU_ASSERT_EQUAL(i_ret,FR_FAIL);

}

int add_suite()
{
	CU_pSuite pSuite = NULL;

	pSuite = CU_add_suite("t_frcmd_talking 测试", __suite_init, __suite_cleanup);

	if (NULL == pSuite)
	{
		return 1;
	}


    //增加测试用例
   	CU_add_test(pSuite, "case1", case1);

   	CU_add_test(pSuite, "case2", case2);

   	CU_add_test(pSuite, "case3", case3);


    return 0;

}

int main(int argc, char **argv)
{
    frmem_init();
    run_cunit(add_suite);
    frshow_leak();
    frmem_destroy();
    return 0;
}